let Users = require('./../../model/users');

let login = async function(ctx, next) {
    let body = ctx.request.body;
    let users = new Users();
    let data = '';
    let msg = '';
    let _isMobile = await users.findMobile(body.mobile);
    console.log(_isMobile)
    if (!_isMobile) {
        ctx.body = new resModel.Def('该账号不存在')
    } else {
        let cb = await users.findMobilePas(body.mobile, body.password);
        if (!cb) {
            ctx.body = new resModel.Error('密码错误')
        } else {
            data = {
                token: sess.generateToken(cb._id, cb.mobile, cb.password),
                _id: cb._id
            }
            ctx.body = new resModel.Success(data, '登录成功')
        }
    }
}


module.exports = {
    login
}